
#ifndef __CORTISOL_SWSCALE_LIB_H
#define __CORTISOL_SWSCALE_LIB_H

class SWScaleLib
{
	HMODULE handle;

	typedef struct SwsContext* (*sws_getContext_fptr_t)(int srcW, int srcH, enum PixelFormat srcFormat,
                                  int dstW, int dstH, enum PixelFormat dstFormat,
                                  int flags, SwsFilter *srcFilter,
                                  SwsFilter *dstFilter, const double *param);

	typedef void (*sws_freeContext_fptr_t)(struct SwsContext *swsContext);

	typedef int (*sws_scale_fptr_t)(struct SwsContext *context, const uint8_t* const srcSlice[], const int srcStride[],
              int srcSliceY, int srcSliceH, uint8_t* const dst[], const int dstStride[]);


	sws_getContext_fptr_t		sws_getContext_fptr;
	sws_freeContext_fptr_t		sws_freeContext_fptr;
	sws_scale_fptr_t			sws_scale_fptr;

public:

	SWScaleLib() {

		Initialise();
	}

	virtual ~SWScaleLib() {

		CleanUp();
	}

	struct SwsContext* sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
                                  int dstW, int dstH, enum PixelFormat dstFormat,
                                  int flags, SwsFilter *srcFilter,
                                  SwsFilter *dstFilter, const double *param) const {

		return sws_getContext_fptr( srcW,srcH,srcFormat,dstW,dstH,dstFormat,flags,srcFilter,dstFilter,param );
	}

	void sws_freeContext(struct SwsContext *swsContext) const {

		sws_freeContext_fptr( swsContext );
	}

	int sws_scale(struct SwsContext *context, const uint8_t* const srcSlice[], const int srcStride[],
              int srcSliceY, int srcSliceH, uint8_t* const dst[], const int dstStride[]) const {

		return sws_scale_fptr(context,srcSlice,srcStride,srcSliceY,srcSliceH,dst,dstStride);
	}

private:

	void Initialise() {

		if((handle = LoadLibrary( L"swscale-0.dll" )) == NULL)
			throw Exception("LoadLibrary( L\"swscale-0.dll\" )");

		RESOLVE( sws_getContext );
		RESOLVE( sws_freeContext );
		RESOLVE( sws_scale );
	}

	void CleanUp() {

		FreeLibrary( handle );
	}

};

#endif /*** __CORTISOL_SWSCALE_LIB_H ***/

